package com.example;


import com.example.mapper.CustomerMapper;
import com.example.mapper.OrderMapper;
import com.example.mapper.UserMapper;
import com.example.pojo.Customer;
import com.example.pojo.Order;
import com.example.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
@Slf4j
public class test {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private UserMapper userMapper;

    @Test
    public void test1() {
        Order order = orderMapper.selectOrderWithCustomer(1);
        System.out.println(order);

    }

    @Test
    public void test2() {
        Customer customer = customerMapper.selectCustomerWithOrderList(1);
        log.info("customer.getCustomerId() = " + customer.getCustomerId());
        log.info("customer.getCustomerName() = " + customer.getCustomerName());
        List<Order> orderList = customer.getOrderList();
        for (Order order : orderList) {
            log.info("order = " + order);
        }

    }

    @Test
    public void test3() {
        User user = new User();
        user.setUsername("shabi");
        user.setPassword("jiushini");
        int insert = userMapper.insert(user);
        log.info("insert = " + insert);
        log.info("user = " + user);
    }

    @Test
    public void test4() {
        User user = new User();
        user.setUsername("shabi");
        user.setPassword("shini");
        user.setId(1);
        userMapper.update(user);
    }


    @Test
    public void test5() {
        User user = new User();
        userMapper.delete(1);
    }

    @Test
    public void test6() {
        User user = userMapper.selectById(2);
        log.info("user = " + user);
    }

    @Test
    public void test7() {
        for (int i = 0; i < 10; i++) {
            test3();
        }
    }

    @Test
    public void test8() {
        List<User> users = userMapper.selectAll();
        for (User user : users) {
            log.info("user = " + user);
        }
    }


}
